﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.ActiveRecord;
using System.ComponentModel.DataAnnotations;
using NHibernate.Mapping;

namespace ZDSoft.LMS.Domain
{
    [ActiveRecord("SystemFunction")]
    public class SystemFunction : EntityBase
    {
        /// <summary>
        /// 系统功能名称
        /// </summary>
        [Property(NotNull = true, Length = 20)]
        [Required(ErrorMessage = "不能为空")]
        [StringLength(10, ErrorMessage = "不能超过10个字符")]
        [Display(Name = "名称")]
        public string SystemFunctionName { get; set; }

        /// <summary>
        /// 系统功能类名
        /// </summary>
        [Property(NotNull = true, Length = 200)]
        [Required(ErrorMessage = "不能为空")]
        [StringLength(200, ErrorMessage = "不能超过200个字符")]
        [Display(Name = "类名")]
        public string ClassName { get; set; }

        /// <summary>
        /// 控制器名称
        /// </summary>
        [Property(Length = 50)]
        [Required(ErrorMessage = "不能为空")]
        [StringLength(50, ErrorMessage = "不能超过50个字符")]
        [Display(Name = "控制器名称")]
        public string ControllerName { get; set; }

        /// <summary>
        /// Action名称
        /// </summary>
        [Property(Length = 200)]
        [Required(ErrorMessage = "不能为空")]
        [StringLength(50, ErrorMessage = "不能超过50个字符")]
        [Display(Name = "Action名称")]
        public string ActionName { get; set; }

        [Property]
        [Display(Name = "序号")]
        public int Idx { get; set; }

        /// <summary>
        /// 父级功能
        /// </summary>
        [BelongsTo(Column = "ParentID",NotNull = false, Cascade = CascadeEnum.None,Lazy= FetchWhen.OnInvoke)]
        [Required(ErrorMessage = "不能为空")]
        public SystemFunction Parent { get; set; }

        /// <summary>
        /// 子功能
        /// </summary>
        [HasMany(typeof(SystemFunction), ColumnKey = "ParentID",Cascade = ManyRelationCascadeEnum.None, Inverse = true,Lazy = true)]
        public IList<SystemFunction> Children { get; set; }

        /// <summary>
        /// 可以操作当前功能的角色
        /// </summary>
        [HasAndBelongsToMany(typeof(Role), Table = "Role_SystemFunction", ColumnKey = "SystemFunctionID", ColumnRef = "RoleID", Cascade = ManyRelationCascadeEnum.All, Inverse = false,Lazy = true)]
        public IList<Role> Roles { get; set; }
    }
}
